//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using CommunityServer.Components;
using CommunityServer.Galleries.Components;
namespace CommunityServer.Galleries.Controls
{
	/// <summary>
	/// Enables the default layout of a page to be specified and overriden
	/// </summary>
	public class Page : GalleryThemedControl
	{
		public Page() : base()
		{
			CSContext csContext = CSContext.Current;

			if(!Globals.IsNullorEmpty(csContext.PostName))
			{
				GalleryThreadQuery query = new GalleryThreadQuery();

				query.PostName = csContext.PostName;
				query.RequireSectionIsActive = true;

				ThreadSet ts = GalleryPosts.GetPictures(query, false);

				if(ts.TotalRecords > 0)
				{
					csContext.PostID = ((Post)ts.Threads[0]).PostID ;
				}
			}

		}

		private string _view;
		public string View
		{
			get{ return _view;}
			set{ _view = value;}
		}

		protected override string ExternalSkinFileName
		{
			get { return string.Format("Views/View-{0}.ascx", View); }
		}

		protected override void Render(System.Web.UI.HtmlTextWriter writer)
		{
			SetDocType(writer);
			base.Render (writer);
		}
		[System.Diagnostics.Conditional("DEBUG")]
		protected void SetDocType(System.Web.UI.HtmlTextWriter writer)
		{
			writer.WriteLine(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Frameset//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"">") ;
		}


		/// <summary>
		/// Override this method to attach templated or external skin controls to local references.
		/// </summary>
		protected override void AttachChildControls()
		{
		}
	}
}
